Skip to content

Fix: Make WASAPI loopback buffer size adaptive to device capabilities#344

Open
anshul23102 wants to merge 1 commit into
SamXop123:mainfrom
anshul23102:fix/issue-331-adaptive-buffer-size
Open

Fix: Make WASAPI loopback buffer size adaptive to device capabilities#344
anshul23102 wants to merge 1 commit into
SamXop123:mainfrom
anshul23102:fix/issue-331-adaptive-buffer-size

Conversation

@anshul23102

@anshul23102 anshul23102 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the WASAPI loopback buffer being hardcoded to a fixed size that's incompatible with high-performance audio devices. The buffer duration is now dynamically determined based on the device's minimum supported period with a 10ms floor.

Changes

  • Modified WasapiLoopbackCapture constructor to query device period capabilities via GetDevicePeriod
  • Compute buffer duration as Math.Max(minimumPeriod, 10ms) to adapt to hardware capabilities
  • Pass computed duration to AudioClient.Initialize instead of fixed 0

Testing

Verified on high-performance audio interfaces that visualization no longer exhibits stuttering artifacts. The buffer now respects device latency constraints while maintaining compatibility across different hardware setups.

Related

Closes #331

Summary by CodeRabbit

  • Bug Fixes
    • Improved audio loopback capture initialization by adapting buffer sizing to the device’s minimum supported period.
    • Increased reliability across devices while maintaining a minimum 10 ms capture buffer.

The WASAPI loopback buffer was using a fixed size that could be incompatible
with high-performance audio devices. This caused audio stuttering and irregular
visualization spikes on systems with low-latency hardware.

Now the buffer duration is determined dynamically based on the device's minimum
supported period, with a minimum floor of 10ms to ensure compatibility across
different hardware setups.

Fixes SamXop123#331

Signed-off-by: Anshul Jain <aj.ts1758@gmail.com>
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

@anshul23102 is attempting to deploy a commit to the Dot_NotSam's projects Team on Vercel.

A member of the Team first needs to authorize it.

@anshul23102

Copy link
Copy Markdown
Contributor Author

@SamXop123 /assign /claim

I've assigned this issue to myself and claimed it as part of GSSoC 2026. Please apply the gssoc:approved label when ready.

This PR addresses the WASAPI loopback buffer size limitation that was causing audio stuttering on high-performance systems by making the buffer duration adaptive to the device's capabilities.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

WASAPI loopback capture now queries the device period and initializes its shared-mode audio buffer using the larger of that period or 10ms, while retaining zero periodicity.

Changes

WASAPI loopback capture

Layer / File(s) Summary
Compute and apply the capture buffer
audio-helper/Program.cs
WasapiLoopbackCapture derives bufferDuration from the device period with a 10ms minimum and passes it to IAudioClient.Initialize.

Estimated code review effort: 2 (Simple) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The change matches #331 by deriving buffer duration from GetDevicePeriod with a 10 ms minimum instead of a fixed buffer.
Out of Scope Changes check ✅ Passed No unrelated code changes are indicated beyond the WASAPI buffer sizing update.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: making the WASAPI loopback buffer adaptive to device capabilities.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@SamXop123 SamXop123 added good first issue Good for newcomers gssoc:approved review gssoc26 GirlScript Summer of Code 2026 labels Jul 10, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
audio-helper/Program.cs (1)

126-127: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider discarding the unused defaultPeriod.

defaultPeriod is captured via out var but never read. Using a discard (out _) clarifies intent and avoids a dangling variable.

♻️ Optional cleanup
-        Marshal.ThrowExceptionForHR(_audioClient.GetDevicePeriod(out var defaultPeriod, out var minimumPeriod));
+        Marshal.ThrowExceptionForHR(_audioClient.GetDevicePeriod(out _, out var minimumPeriod));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@audio-helper/Program.cs` around lines 126 - 127, Replace the unused
defaultPeriod variable in the _audioClient.GetDevicePeriod call with a discard
(out _) while preserving minimumPeriod for the bufferDuration calculation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@audio-helper/Program.cs`:
- Around line 126-127: Replace the unused defaultPeriod variable in the
_audioClient.GetDevicePeriod call with a discard (out _) while preserving
minimumPeriod for the bufferDuration calculation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 926e182f-8ac1-42a2-afb2-119583f1fdab

📥 Commits

Reviewing files that changed from the base of the PR and between 68edfe4 and 4c578bc.

📒 Files selected for processing (1)
  • audio-helper/Program.cs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

good first issue Good for newcomers gssoc:approved gssoc26 GirlScript Summer of Code 2026 review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: C# WASAPI loopback buffer size fixed at 100ms, causes stuttering at low latency

2 participants